package org.jeecg.modules.demo.ch.common;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.poi.ss.formula.functions.T;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@ApiModel
@Data
public class PageList<S> implements Serializable {
    private static final long serialVersionUID = 1412759446332294208L;

    @ApiModelProperty(value = "每页数量")
    private long size;

    @ApiModelProperty(value = "当前页")
    private long current;

    @ApiModelProperty(value = "数据总条数")
    private long total;


    @ApiModelProperty(value = "总页数")
    private long pages;


    @ApiModelProperty(value = "数据LIST")
    private List<S> records = new ArrayList<S>();

    @ApiModelProperty(value = "数据合计")
    private Object dataTotal;


    public PageList() {
    }

    public PageList(long current, long size, long total) {
        this.current = current;
        this.size = size;
        this.total = total;
        this.pages = (int) Math.ceil((double) total / size);
    }


    public PageList(IPage<T> page) {
     //   this.records.addAll(page.getRecords());
        this.total =  page.getTotal();
        this.size =   page.getSize();
        this.current = page.getCurrent();
        this.pages = page.getPages();
    }
}
